﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace F2S.LINQ2LinkedIn.Client.Behaviors
{
    /// <summary>
    /// Helper for converting objects to different types.
    /// </summary>
    public static class ConverterHelper
    {

        /// <summary>
        /// Attempts to convert the provided value to the specified type
        /// </summary>
        /// <param name="value">object to be converted</param>
        /// <param name="type">Type to be converted to</param>
        /// <returns></returns>
        public static bool CheckValues(object value, object bindingValue)
        {
            if (value == null)
                return false;

            if (value is string && bindingValue is string)
            {
                return value as string == bindingValue as string;
            }

            if (value is bool && bindingValue is bool)
            {
                var b1 = (bool)value;
                var b2 = (bool)bindingValue;
                return b1 == b2;
            }

            if (value is string && bindingValue is bool)
            {
                var b1 = Convert.ToBoolean(value);
                var b2 = (bool)bindingValue;
                return b1 == b2;
            }


            return false;
        }

    }
}
